//
//  SceneDelegate.swift
//  imprint
//
//  Created by 小柠檬🍋 on 2025/3/22.
//

// SceneDelegate.swift
import UIKit
import SwiftUI

class SceneWxDelegate  : UIResponder, UIWindowSceneDelegate {

//    var window: UIWindow?
////
//    func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
//        guard let windowScene = (scene as? UIWindowScene) else { return }
//        window = UIWindow(windowScene: windowScene)
//        // 这里可以设置根视图控制器，例如使用 SwiftUI 视图
//        let contentView = Text("Hello, World!")
//        let hostingController = UIHostingController(rootView: contentView)
//        window?.rootViewController = hostingController
//        window?.makeKeyAndVisible()
//    }
////
//    func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
//        guard let url = URLContexts.first?.url else { return }
//        if WXApi.handleOpen(url, delegate: self) {
//            showLog("成功处理微信 URL 回调")
//        } else {
//            showLog("处理微信 URL 回调失败")
//        }
//    }
//
//    func scene(_ scene: UIScene, continue userActivity: NSUserActivity) {
//        if userActivity.activityType == NSUserActivityTypeBrowsingWeb, let url = userActivity.webpageURL {
//            if WXApi.handleOpenUniversalLink(userActivity, delegate: self) {
//                showLog("成功处理微信 Universal Link 回调")
//            } else {
//                showLog("处理微信 Universal Link 回调失败")
//            }
//        }
//    }
}

extension SceneWxDelegate: WXApiDelegate {
    func onResp(_ resp: BaseResp) {
        if let authResp = resp as? SendAuthResp, resp.errCode == 0 {
            if let code = authResp.code {
                showLog("授权成功")
                getLogin(type: LoginType.WX)?.doAuthSuc(code: code)
            }
          
        } else {
            showToast("授权失败")
        }
    }
}
